Game Services
Introduction
Game services provide tools that let you easily integrate popular gaming features, such as Player Identity and Saved Games, into your mobile and tablet games.
Leverage Plankton's Game Services functionality to seamlessly handle saving/loading user profiles and signing them in with either Google Play Games Services (v2) on Android or Apple's Game Center on iOS.
In the upcoming sections, you'll find in-depth instructions on integrating the Plankton Game Services feature into your Unity project for both platforms.
Before you begin
Prerequisites
- Complete the Plankton setup
- For Android
- Set Target API Level to
28
or higher - Set Minimum Api Level to
19
or higher
- Set Target API Level to
- For iOS
- Set Target Minimum iOS Version to
15.0
or higher
- Set Target Minimum iOS Version to
You can change Minimum and Target versions in Unity from Edit > Project Settings > Player > Other Settings
Set up your accounts
Android
The Google Play Console is where you manage Google Play games services for your game, and configure metadata for authorizing and authenticating your game. For more information, see Setting Up Google Play Games Services.
After adding your game to Google Play Console and generating an OAuth 2.0 client ID, retrieve the application ID which can be found at the top of the Configuration page and is labeled as Project ID below the name of your game.
The application ID is a required string consisting only of the digits (typically 12 or more) at the beginning of the client ID provided by the Google Play Console.
iOS
Before submitting your app for review, Game Center must be configured in App Store Connect for any apps offering Game Center features. Once you've uploaded your game with Game Center functionality to TestFlight, follow these steps to enable Game Center:
- In the App Store Connect dashboard, go to Apps and select your app.
- In the sidebar, click the app version you want to enable for Game Center.
- Scroll down to the Game Center section and check the box to enable it.
If you've heard about needing to add entitlements or configure something in Xcode, don’t worry! Plankton takes care of all Game Center entitlements automatically, so you won't need to do any extra setup.
Confiure Plankton settings
- Open plankton settings by going to
Edit > Project Settings > Plankton
. - Select the checkbox next to the
Google Play Services
for Android or theGame Center
for iOS - For Google Play Services fill the
App Id
field with your Application ID
Implementation
It's time to write a few lines of code. Always import the Plankton
package in your scripts.
using Plankton;
Initialize
Before using any functionality of Game Services, you must call the Initialize
method.
This method prepares the service and allows you to listen for sign-in status changes:
GameServices.Initialize(onSignInCallback: signedIn =>
{
Debug.Log($"Game Services Sign-in Status: signedIn={signedIn}");
});
The onSignInCallback
provides a boolean indicating whether the player is currently signed in or not.
You can use this to update your UI or enable features based on sign-in status.
On Android, Google Play Games Services automatically launches the sign-in flow at the start of the game.
The result of this automatic process is reflected in the callback of the Initialize
method, so you can check whether the sign-in was successful or not.
You can also manually trigger the sign-in process at any time by calling SignIn
, if needed.
Sign In
To access Game Services features, your game must authenticate the player by signing them into their account. On Android, Google Play Games Services automatically attempts to sign the player in when the game starts. You can also manually trigger the sign-in flow at any time on both Android and iOS by calling:
GameServices.SignIn();
The result of both the automatic and manual sign-in flows will be available through the same callback you passed to the Initialize
method.
Silent Sign-In
On iOS, the sign-in process is handled silently using the iCloud account that the player is already signed into on their iPhone or iPad. A sign-in dialog will only appear if no active iCloud account is detected on the device.
On Android, depending on the player's preferences in the Play Games app, the sign-in process may either happen silently or prompt the user every time.
In both platforms, when a silent sign-in occurs successfully, a welcoming message will be automatically shown to inform the player that they are signed in.
Check if the user is signed in
You can ensure that the user is signed in or not anytime simply using the IsSignedIn
property:
bool isSignedIn = GameServices.IsSignedIn;
Accessing Player Info
After initializing Game Services and completing sign-in, you can retrieve basic player information by calling:
GameServices.GetPlayerInfo(result => {
if (result.success)
{
Debug.Log($"Player ID: {result.playerId}, Display Name: {result.displayName}");
}
else
{
Debug.Log("Failed to get player info.");
}
});
The result is returned as an object of type PlayerInfo
, which contains fields like success
, playerId
, and displayName
.
In Plankton version 3.4.1 and earlier, the player identity was provided as userId
.
Starting from version 3.5.0, this parameter is renamed to playerId
to align with platform-specific standards:
- On iOS,
playerId
remains unchanged and equals the Game Center "gamePlayerId". - On Android,
playerId
is a new unique identifier per player, per game, consistent across devices but different from the previoususerId
.
If your game relies on the old userId
for identifying players, note that it's no longer accessible on the client-side.
You can retrieve the previous userId
using Google Play's server-side APIs and match them with the new playerId
where needed.
Server-Side Access
If your game communicates with a secure backend server, you can use server-side access to safely verify player identity and handle sensitive data. Instead of sending player details directly from the device, this method allows your backend to authenticate the player using secure tokens, reducing the risk of tampering.
Once the player signs in successfully, you can request platform-specific parameters from Plankton to help your backend securely verify the player's identity. On Android, this provides a single-use server auth code, which your server exchanges for OAuth tokens to access Google Play Games Services. On iOS, you receive public key data used to verify the player identity on your backend.
To retrieve this information:
GameServices.GetServerSideParams(result => {
if (result.success)
{
Debug.Log($"Android - Server auth code: {result.androidAuthCode}");
Debug.Log($"iOS - Public key URL: {result.iosPublicKeyUrl}, signature: {result.iosSignature}, salt: {result.iosSalt}, timestamp: {result.iosTimestamp}");
}
});
The full list of returned fields is available in the ServerSideParams
class reference.
Android Setup
To use this feature on Android:
- Open Plankton Settings > enalbe Google Play Services
- Enable the Server Side Access option
- Enter your OAuth Client ID (Server Client ID), which you generate in your Google Play Console by creating a credential of type "web" for your game server. Learn more
iOS Setup
No additional setup is required on iOS to retrieve the server-side parameters.
Saved Games
The Saved Games feature provides a convenient way to store and retrieve your players' game progress across devices. On Android, it utilizes Google Play Games Services, while on iOS, it leverages iCloud through Game Center.
This allows players to seamlessly continue their game from their last save point, even if they uninstall and reinstall the game on the same device or switch to a different one.
Plankton enables saving and loading a user's data through GameServices.Save
and GameServices.Load
methods.
Save
To store data you can call:
GameServices.Save("Filename", "Data to be saved", "Developer description", succeed => Debug.Log($"Save result:{succeed}"));
This method has four arguments:
- filename which act as a key to create multiple saved games with different names
- the savedData which is a
string
value that is going to be stored on the player's account. - description is a developer-supplied description of the saved game.
- a callback argument which gets called when the save process is finished. It returns a
bool
parameter indicating whether it was succcessful or not.
The saved data can be a serialized form of a user profile that you know how to deserialize. For example, it can be in the JSON format or any other format you prefer.
Load
For loading the data that you have saved earlier, you can call:
GameServices.Load("Filename", data => Debug.Log($"Load result:{data}"));
This method has two argument:
- filename which act as a key to create multiple saved games with different names
- a callback argument which gets called when the loading process is finished. It returns a
string
parameter containing the saved data.
If the loading process fails or it doesn't find any saved games, the returned data in the callback of Load
method will be empty.
API Refrences
Defined Types
In this section, we will discuss the classes associated with this feature:
Classes
GameServices.PlayerInfo
Name | Type | Default Value | Description | Platform |
---|---|---|---|---|
success | bool | false | A flag indicating if the player info was retrieved successfully | Android/iOS |
playerId | string | string.Empty | A unique identifier for the player. On iOS, this is the Game Center gamePlayerId . On Android, this is a unique per-player, per-game ID, consistent across devices but different from older userId . | Android/iOS |
displayName | string | string.Empty | The player's visible name | Android/iOS |
GameServices.ServerSideParams
Name | Type | Default Value | Description | Platform |
---|---|---|---|---|
success | bool | false | A flag indicating if the server-side parameters were retrieved successfully | Android/iOS |
androidAuthCode | string | string.Empty | A one-time server auth code for your backend server to exchange for an access token | Android |
iosPublicKeyUrl | string | string.Empty | The URL for the public encryption key | iOS |
iosSignature | string | string.Empty | The verification signature that GameKit generates | iOS |
iosSalt | string | string.Empty | A random string used by GameKit to compute the hash | iOS |
iosTimestamp | long | 0 | The timestamp of the signature's creation | iOS |
Method Summaries
Method | Arguments | Return Type | Description |
---|---|---|---|
Initialize | Action<bool> onSignInCallback | void | Initializes the Game Services module. Must be called before other methods. The callback provides a boolean indicating whether the player is signed in or not. On Android, Google Play Games automatically attempts silent sign-in at startup; the callback reflects the result. You can manually trigger sign-in with the SignIn() method. |
SignIn | (no arguments) | void | Manually starts the sign-in process for both Android and iOS. The result of the sign-in attempt is provided through the callback passed to Initialize . On Android, depending on the player's settings in the Play Games app, sign-in may happen silently or via a pop-up. On iOS, sign-in uses the iCloud account and displays a dialog only if no iCloud account is active. |
GetPlayerInfo | Action<PlayerInfo> callback | void | Retrieves the signed-in player's information such as their unique ID and display name. The result is returned via the callback as a PlayerInfo object. |
GetServerSideParams | Action<ServerSideParams> callback | void | Provides authentication parameters required for secure server-side access. On Android, ensure you enable server-side access in Plankton's settings and set your OAuth client ID. The result is returned via the callback as a ServerSideParams object. |
Save | string fileName, string json, string description, Action<bool> callback | void | Saves a string value (e.g., JSON-encoded game state) using Google Play Services on Android or iCloud on iOS. fileName specifies the saved data name, json is the data, description is an optional description (Android only), and callback returns whether the save was successful. |
Load | string fileName, Action<string> onCompleted | void | Loads previously saved data for the user by specifying the fileName . The result is returned as a string via the callback. |